package org.webdb.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCColumn {

    private String name;
    private boolean primaryKey;
    private String schema;
    private ValueStrategy strategy = null;
    private String table;
    private int type;
    private String typeName;

    public JDBCColumn(ResultSet resultSet, String schemaName, String tableName)
            throws SQLException {
        name = resultSet.getString(4);
        type = resultSet.getInt(5);
        typeName = resultSet.getString(6);
        schema = schemaName;
        table = tableName;
    }

    public String getName() {
        return name;
    }

    public String getSchema() {
        return schema;
    }

    public String getTable() {
        return table;
    }

    public int getType() {
        return type;
    }

    public String getTypeName() {
        return typeName;
    }

    public boolean isPrimaryKey() {
        return primaryKey;
    }

    public void setPrimaryKey(boolean primaryKey) {
        this.primaryKey = primaryKey;
    }

    public void setStrategy(ValueStrategy strategy) {
        this.strategy = strategy;
    }

    @Override
    public String toString() {
        return JDBCColumn.class.getSimpleName() + "[" + name + "]";
    }

    public boolean hasAutoStrategy() {
        return strategy != null;
    }

    public ValueStrategy getStrategy() {
        return strategy;
    }

}
